<template>
  <BasicModal :show="show" title="离岗" width="30%" :widthComfirm="true" @comfirm="submitForm" @closeModal="show = false">
    <template #content>
      <a-form ref="formRef" :model="form" :rules="rules" :label-col="{ style: { width: '100px', textAlign: 'right' } }">
        <a-form-item label="离岗时间" name="range">
          <a-range-picker v-model:value="form.range" style="width: 100%;" value-format="YYYY-MM-DD"
            :date-format="'YYYY年MM月DD日'" :format="'YYYY年MM月DD日'" />
        </a-form-item>
        <a-form-item label="离岗原因" name="reason">
          <a-textarea v-model:value="form.reason"  />
        </a-form-item>
      </a-form>
    </template>
  </BasicModal>
</template>

<script setup lang='ts'>
import { ref } from "vue"
import type { Rule } from 'ant-design-vue/es/form';
import BasicModal from "./BasicModal.vue";
import { message } from "ant-design-vue";
import { internshipProgress } from "@/api/application-details/index.ts";
import { comStores } from '@/store/common/comStore';
const store = comStores()
const { userName } = store.userInFor
const show = ref<boolean>(false);
const form = ref({
  range: [],
  reason: ""
})
const rules: Record<string, Rule[]> = {
  reason: [{ required: true, message: '请填写评价', trigger: 'change' }],
  range: [{ required: true, message: '请选择离岗时间', trigger: 'change' }],
};

const formRef = ref<any>(null)
const emits = defineEmits(['confirm'])
const submitForm = async () => {
  const res = await formRef.value.validate();
  if (!res) return;
  const { resumeId, processId } = store.currentResume;
  let param: any = {
    editStatus: 'OUT_DUTY',
    resumeId: resumeId,
    processId: processId,
    operator: userName,
    outDutyReason: form.value.reason,
    outDutyTime: form.value.range.join(','),
    onDutyStatus:"1"
  }
  const data = await internshipProgress(param);
  if (data && data.code == '10000') {
    store.getResumeInfo(resumeId)
    show.value = false;
    form.value.reason = ""
    form.value.range = []
    message.success("操作成功");
    emits("confirm");
  } else {
    message.error(data.msg)
  }
}
defineExpose({ show })
</script>

<style lang="less" scoped>
.progress {
  display: flex;
  justify-content: end;
  margin: 24px 0;
  padding-top: 24px;
  ;
  font-weight: 400;
  font-size: 14px;
  color: #333333;

  .desc {

    font-weight: 400;
    font-size: 14px;
    color: #209EE4;

  }
}
</style>